package com.shen.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shen.eduservice.client.VodClient;
import com.shen.eduservice.entity.EduVideo;
import com.shen.eduservice.mapper.EduVideoMapper;
import com.shen.eduservice.service.EduVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author shenkaituo
 * @since 2020-06-21
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {

    @Autowired
    VodClient vodClient;
    //根据课程id删除小节
    //todo 删除小节视频
    @Override
    public void removeVideoByCourseId(String id) {
        QueryWrapper<EduVideo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("course_id",id);

        QueryWrapper<EduVideo> videoQueryWrapper=new QueryWrapper<>();
        videoQueryWrapper.select("video_source_id");
        videoQueryWrapper.eq("course_id",id);
        List<EduVideo> eduVideoList = baseMapper.selectList(videoQueryWrapper);
        System.out.println(eduVideoList);
        //得到list<String>
        List<String> videoList=new ArrayList<>();
        //System.out.println(videoList);//[]
        // for 循环的对象写错了
        for(int i=0;i<eduVideoList.size();i++){
            EduVideo eduVideo=eduVideoList.get(i);
            if(!StringUtils.isEmpty(eduVideo)){
                videoList.add(eduVideo.getVideoSourceId());
            }


        }
        System.out.println(videoList);
        //根据多个视频id删除多个视频小节
        if(videoList.size()>0) {
            System.out.println("delete 视频");
            vodClient.removeVideos(videoList);
            System.out.println("videlist is"+videoList);

        }


        baseMapper.delete(queryWrapper);


    }
}
